// @ts-nocheck
import React from 'react';
import {Modal, Form, Input, message} from 'antd'
import {modifyPassword} from '@/services/contract'

const ModifyPassword = (props) => {
  const {visible, onOk, onClose, data} = props
  const [form] = Form.useForm()
  const handleOk = () => {
    form.validateFields().then(value => {
      const body = {
        contract_id: data.contract_id,
        account_number: data.account_number,
        account_password: value.password,
        service_package: data.service_package,
        end_date: data.end_date
      }
      modifyPassword(body).then(res => {
        if (res.status === 200) {
          message.success(res.message).then()
          onOk()
          form.resetFields()
        } else {
          message.error('密码修改失败！').then()
        }
      })
    })
  }
  return (
    <Modal
      destroyOnClose
      title={'密码变更'}
      visible={visible}
      width={'20vw'}
      maskClosable={false}
      onOk={() => handleOk()}
      onCancel={() => {
        onClose();
        form.resetFields()
      }}
    >
      <Form form={form} labelCol={{span: 6}} wrapperCol={{span: 14}} autoComplete="off">
        <Form.Item label="账号密码" name="password" rules={[{required: true, message: '请输入账号密码'}]}>
          <Input.Password placeholder={'请输入账号密码'} allowClear/>
        </Form.Item>
        <Form.Item label="确认密码" name="check" rules={[{required: true, message: '请确认密码'}, ({getFieldValue}) => ({
          validator(_, value) {
            if (!value || getFieldValue('password') === value) {
              return Promise.resolve();
            }
            return Promise.reject(new Error('两次密码不一致!'));
          },
        }),]}>
          <Input.Password placeholder={'请确认密码'} allowClear/>
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default ModifyPassword;
